#ifndef CNETWORK_H
#define CNETWORK_H

#include <QObject>

#include <QTcpServer>
#include <QTcpSocket>

#include <QList>
#include <QMap>

#include <QFile>

#include "../Models/MCharacter.h"
#include "../Models/MStaticData.h"
#include "../Views/VAuthentication.h"

class CNetwork : public QObject
{
    Q_OBJECT
    private:
        QTcpServer *server;


        CNetwork();
        ~CNetwork();

        static CNetwork* singleton;
    public:
        static CNetwork* get_instance();

        // Getters
        QTcpServer* get_server();
        QMap <QTcpSocket*, MCharacter*> clients;

    signals:
        void is_connect();
        void is_connect(QTcpSocket *);
        void is_receiving();

        void login(QTcpSocket *);
        void move(QTcpSocket *);
        void bomb(QTcpSocket *, int, int);
        void get_map(QTcpSocket *);

        void disconnected();
        void disconnected(QTcpSocket *);

    public slots:
        bool start_listen(quint16 port);
        QTcpSocket* wait_connection();

        void send(QTcpSocket* socket, QString message);
        void send_map(QTcpSocket* socket);
        QString receive(QTcpSocket* socket);

        void select_action();
        void select_action(QTcpSocket* socket);
        void close();
};

#endif // CNETWORK_H
